home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.tar / ftp.whtech.com / datasheets and manuals / Hardware / WHT / scsi / dsr_sources_2_2001 / rename < prev    next >
Text File  |  2006-10-19  |  15KB  |  649 lines

  1. ************************************************************
  2. *                                                          *
  3. *  GPL routine >23 - File/subdir rename                    *
  4. *                                                          *
  5. *  Inputs:                                                 *
  6. *     >834C - SCSI device number and buffer bit            *
  7. *     >834E - Pointer to new name                          *
  8. *     >8350 - Pointer to old name                          *
  9. *                                                          *
  10. * Outputs:                                                 *
  11. *    >8350 - Error code                                    *
  12. * Errors returned                                          *
  13. *     Old file does not exist - 7 file error               *
  14. *     Old file is protected   - 1                          *
  15. *     Another file with new name already exists - 7        *
  16. *                                                          *
  17. * Modifications:                                           *
  18. *   Feb 28, 1997 - Had to completely rewrite routine       *
  19. *     because it was taking too much space in memory       *
  20. *                                                          *
  21. ************************************************************
  22.  
  23. RENAM0 ANDI R12,>FF00
  24.        AI   R12,24
  25.  
  26. * Lets start off by copying the old name and new name
  27. * to a buffer in the SCSI card memory
  28. *
  29.        LI   R2,10
  30.        LI   R3,RNOLD
  31.        LDCR @B02,4
  32.        MOVB @>834C,R0        See if filename is in CPU or VDP RAM
  33.        ANDI R0,>8000
  34.        JEQ  RENAM3
  35.  
  36.        MOV  @>8350,R4        Get pointer to old name in CPU memory
  37. RENAM1 MOVB *R4+,*R3+
  38.        DEC  R2
  39.        JNE  RENAM1
  40.  
  41.        MOV  @>834E,R4        Get pointer to new name in CPU memory
  42.        LI   R3,RNNEW
  43.        LI   R2,10
  44. RENAM2 MOVB *R4+,*R3+
  45.        DEC  R2
  46.        JNE  RENAM1
  47.        JMP  RENAM6
  48.  
  49. RENAM3 MOV  @>8350,R4        Get pointer to old name in VDP memory
  50.        SWPB R4               Set VDP read address
  51.        MOVB R4,@VDPWA
  52.        SWPB R4
  53.        MOVB R4,@VDPWA
  54.        NOP
  55. RENAM4 MOVB @VDPRD,*R3+
  56.        DEC  R2
  57.        JNE  RENAM4
  58.  
  59.  MOVB @>834F,@VDPWA
  60.  NOP
  61.  MOVB @>834E,@VDPWA
  62.  
  63.        LI   R3,RNNEW
  64.        LI   R2,10
  65. RENAM5 MOVB @VDPRD,*R3+
  66.        DEC  R2
  67.        JNE  RENAM5
  68. RENAM6
  69.  
  70. * Now we check to see if the parent directory exists
  71. *
  72.        BL   @MAKEFN
  73.        BL   @GETDDR
  74.  
  75.        CI   R5,0             Check that directory exists
  76.        JNE  RENM7
  77.  
  78.        MOVB @B07,@>8350      Set error code
  79.        LDCR @ZERO,4
  80.        B    @DSRRT
  81.  
  82. RENM7  LDCR @B03,4
  83.        MOVB @22(R5),R1       Get # of files in directory
  84.        JEQ  RENM20
  85.  
  86. * Read the FDIR from disk
  87. *
  88.        MOV  @24(R5),R7       Get AU of FDIR
  89.        LDCR @B02,4
  90.        MOV  R7,@RNFDIR       Save AU of FDIR for later
  91.  
  92.        LDCR @B04,4
  93.        MOV  R6,R3
  94.        SRL  R3,8
  95.        SLA  R3,1
  96.        MPY  @SAUTBL(R3),R7
  97.  
  98.        LI   R5,SECBUF
  99.        SRL  R8,1
  100.        JNC  RENM8
  101.        AI   R5,>100
  102. RENM8  SRL  R7,1
  103.        JNC  RENM9
  104.        ORI  R8,>8000
  105. RENM9  LDCR @ZERO,4
  106.        BLWP @BANKIT
  107.        DATA SCSIRD
  108.        JEQ  RENM10
  109.  
  110. RENM9A MOVB @B06,@>8350      Hardware error
  111.        B    @DSRRT
  112.  
  113. RENM10 LI   R2,DFDR          Copy the FDIR to the DFDR
  114.        LI   R3,256           buffer
  115. RENM11 LDCR @ZERO,4
  116.        MOV  *R5+,R4
  117.        LDCR @B02,4
  118.        MOV  R4,*R2+
  119.        DECT R3
  120.        JNE  RENM11
  121.  
  122.        LI   R2,>0200         R2 has the bank
  123.        LI   R3,DFDR          R3 pointer to the list of AUs
  124.  
  125.        BL   @RNDOIT          Let's rename a file!
  126.  
  127. * If it successfully renamed the file, we have to write
  128. * the FDIR back out to disk.
  129.  
  130.        CI   R9,0
  131.        JEQ  RENM20
  132.        CI   R9,1
  133.        JEQ  RENM15
  134.  
  135.        LDCR @B02,4
  136.        MOV  @RNFDIR,R7
  137.        LI   R5,DFDR
  138.        LI   R4,>0200         Bank of DFDR
  139.  
  140. **
  141. *
  142. * Here we write the FDIR or DDR back out to disk.  At this
  143. * point in the program, the following registers must be set.
  144. *
  145. * R4 = Bank # with the DDR or FDIR
  146. * R5 = Pointer to the DDR or FDIR in memory
  147. * R6 = SCSI ID of drive we're writing to
  148. * R7 = AU of DDR or FDIR
  149. *
  150. **
  151.  
  152. RN11A  LDCR @B04,4
  153.        MOV  R6,R3
  154.        SRL  R3,8
  155.        SLA  R3,1
  156.        MPY  @SAUTBL(R3),R7
  157.        LI   R1,SECBUF
  158.        SRL  R8,1
  159.        JNC  RENM12
  160.        AI   R1,>100
  161. RENM12 SRL  R7,1
  162.        JNC  RENM13
  163.        ORI  R8,>8000
  164. RENM13 LDCR @ZERO,4
  165.        BLWP @BANKIT
  166.        DATA SCSIRD
  167.        JNE  RENM9A           Error routine
  168.        LI   R0,256           Copy the FDIR into the buffer
  169. RENM14 LDCR R4,4
  170.        MOV  *R5+,R2
  171.        LDCR @ZERO,4
  172.        MOV  R2,*R1+
  173.        DECT R0
  174.        JNE  RENM14
  175.  
  176.        BLWP @BANKIT
  177.        DATA SCSIWT
  178.        JNE  RENM9A
  179.  
  180. RENM15 LDCR @ZERO,4
  181.        MOVB @ZERO,@>8356
  182.        B    @DSRRT
  183.  
  184. * If we get to here, then there is no filename with the same
  185. * name as what we ant to rename.  Check to see if there is a
  186. * directory with the name and rename that
  187. *
  188. RENM20 BL   @GETDDR
  189.        LDCR @B03,4
  190.        MOVB @23(R5),R1   Get number of subdirectories
  191.        JEQ  RENM21
  192.  
  193.        LI   R2,>0300     R2 = bank of the DDR
  194.        MOV  R5,R3
  195.        AI   R3,28
  196.        BL   @RNDOIT
  197.        CI   R9,0
  198.        JNE  RENM22
  199.  
  200. RENM21 LDCR @ZERO,4      File not found error
  201.        MOVB @B07,@>8350
  202.        B    @DSRRT
  203.  
  204. RENM22 CI   R9,1
  205.        JEQ  RENM15
  206.  
  207. * We have to write the DDR back out to disk
  208. *
  209.        BL   @GETDDR          Get pointer to DDR in R5
  210.        LI   R4,>0300         Bank of DDR in memory
  211.        LDCR @B04,4
  212.        MOV  @SAVEAU,R7
  213.        JMP  RN11A
  214.  
  215. ************************************************************
  216. *                                                          *
  217. *  PROCEDURE: RNDOIT (REname DO IT)                        *
  218. *                                                          *
  219. *  This procedure has been written so that it can rename   *
  220. *  either a file or a directory.  All it needs is a list   *
  221. *  of AUs from either an FDIR or a DDR and will modify     *
  222. *  the file name in the header of the FDR or DDR and       *
  223. *  resequence the list of AUs.  It it the duty of the      *
  224. *  caller to write the list of AUs back out to disk.       *
  225. *                                                          *
  226. *  Inputs:                                                 *
  227. *     RNOLD - Contains the old name of the file or dir     *
  228. *     RNNEW - Contains the new name of the file or dir     *
  229. *     R1 - Number of AUs in the list (MSB)                 *
  230. *     R2 - Bank number of list (MSB)                       *
  231. *     R3 - Points to list of AUs                           *
  232. *                                                          *
  233. *  Output:                                                 *
  234. *     R9 = 0 - File not found                              *
  235. *          1 - File renamed, no need to write list di disk *
  236. *          2 - File renames, write index back to disk      *
  237. *                                                          *
  238. ************************************************************
  239.  
  240. RNDOIT LDCR @B02,4
  241.        SRL  R1,8
  242.        MOV  R1,@RNHIGH
  243.        DEC  R1
  244.        CLR  R0
  245.  
  246.        CLR  @RNLOW
  247.        CLR  @LONAM
  248.        SETO @HINAM
  249.  
  250. * Start by copying the old name to the file name compare
  251. * buffer in bank 0
  252.  
  253.        LI   R4,10
  254.        LI   R5,FNCB
  255.        LI   R7,RNOLD
  256. RNDO1  LDCR @B02,4
  257.        MOV  *R7+,R8
  258.        LDCR @ZERO,4
  259.        MOV  R8,*R5+
  260.        DECT R4
  261.        JNE  RNDO1
  262.  
  263. RNDO2  MOV  R0,R4            Compute the midpoint
  264.        A    R1,R4
  265.        ANDI R4,>FFFE
  266.        A    R3,R4
  267.        LDCR R2,4
  268.        MOV  *R4,R7           Get AU
  269.        LDCR @B02,4
  270.        MOV  R7,@RENMAU       Save AU in case this is the one
  271.  
  272.        LDCR @B04,4
  273.        MOV  R6,R4
  274.        SRL  R4,8
  275.        SLA  R4,1
  276.        MPY  @SAUTBL(R4),R7
  277.  
  278.        LI   R4,SECBUF
  279.        SRL  R8,1
  280.        JNC  RNDO3
  281.        AI   R4,>100
  282. RNDO3  SRL  R7,1
  283.        JNC  RNDO4
  284.        ORI  R8,>8000
  285. RNDO4  LDCR @ZERO,4
  286.        BLWP @BANKIT
  287.        DATA SCSIRD
  288.        JEQ  RNDO4A
  289.  
  290.        MOVB @B06,@>8350      Device error
  291.        B    @DSRRT
  292.  
  293. * Here we compare the name to the new filename.  This will
  294. * help narrow down the search for where the file will go
  295. * after it has been renamed.
  296. *
  297. RNDO4A
  298.        LI   R7,RNNEW
  299.        MOV  R4,R8
  300.        LI   R5,10
  301. RNDO4B LDCR @ZERO,4
  302.        MOV  *R8+,R9
  303.        LDCR @B02,4
  304.        C    R9,*R7+
  305.        JH   RNDO4D
  306.        JL   RNDO4G
  307.        DECT R5
  308.        JNE  RNDO4B
  309.  
  310. * This matched the new name.  We have to set everything
  311. *
  312.        MOV  R0,R7            Recalculate midpoint
  313.        A    R1,R7
  314.        SRL  R7,1
  315.        MOV  R7,@RNLOW
  316.        MOV  R7,@RNHIGH
  317.  
  318.        LI   R7,LONAM
  319.        MOV  R4,R8
  320.        LI   R5,10
  321. RNDO4C LDCR @ZERO,4
  322.        MOV  *R8+,R9
  323.        LDCR @B02,4
  324.        MOV  R9,@10(R7)
  325.        MOV  R9,*R7+
  326.        DECT R5
  327.        JNE  RNDO4C
  328.        JMP  RNDO5
  329.  
  330. RNDO4D LI   R7,HINAM
  331.        MOV  R4,R8
  332.        LI   R5,10
  333. RNDO4E LDCR @ZERO,4
  334.        MOV  *R8+,R9
  335.        LDCR @B02,4
  336.        C    R9,*R7+
  337.        JH   RNDO5
  338.        JL   RNDO4F
  339.        DECT R5
  340.        JNE  RNDO4E
  341.  
  342. * This name is higher than the new name, but lower
  343. * than HINAM.  We need to set the new HINAM and RNHIGH
  344. *
  345. RNDO4F LI   R7,HINAM
  346.        MOV  R4,R8
  347.        LI   R5,10
  348. RNDO4K LDCR @ZERO,4
  349.        MOV  *R8+,R9
  350.        LDCR @B02,4
  351.        MOV  R9,*R7+
  352.        DECT R5
  353.        JNE  RNDO4K
  354.  
  355.        MOV  R0,R7            Recalculate midpoint
  356.        A    R1,R7
  357.        SRL  R7,1
  358.        MOV  R7,@RNHIGH
  359.        JMP  RNDO5
  360.  
  361. **
  362.  
  363. RNDO4G LI   R7,LONAM
  364.        MOV  R4,R8
  365.        LI   R5,10
  366. RNDO4H LDCR @ZERO,4
  367.        MOV  *R8+,R9
  368.        LDCR @B02,4
  369.        C    R9,*R7+
  370.        JH   RNDO4I
  371.        JL   RNDO5
  372.        DECT R5
  373.        JNE  RNDO4H
  374.  
  375. * This name is lower than the new name, but higher
  376. * than LONAM.  We need to set the new LONAM and RNLOW
  377. *
  378. RNDO4I LI   R7,LONAM
  379.        MOV  R4,R8
  380.        LI   R5,10
  381. RNDO4J LDCR @ZERO,4
  382.        MOV  *R8+,R9
  383.        LDCR @B02,4
  384.        MOV  R9,*R7+
  385.        DECT R5
  386.        JNE  RNDO4J
  387.  
  388.        MOV  R0,R7            Recalculate midpoint
  389.        A    R1,R7
  390.        SRL  R7,1
  391.        MOV  R7,@RNLOW
  392.  
  393. * Compare the names to see if we have a match
  394. *
  395. RNDO5  LDCR @ZERO,4
  396.        LI   R5,FNCB
  397. RNDO5A C    *R4+,*R5+
  398.        JL   RNDO6
  399.        JH   RNDO7
  400.        CI   R5,FNCB+10
  401.        JNE  RNDO5A
  402.  
  403. * We have a match !!!
  404.  
  405.        AI   R4,-10
  406.  
  407. * If this is an FDR, see if it is protected.  If so, abort
  408. * here.  If it is not protected, or if this is a DDR,
  409. * continue on.
  410.  
  411.        MOV  @28(R4),R1
  412.        CI   R1,'FI'
  413.        JNE  RNDO10
  414.        MOV  @12(R4),R1
  415.        COC  @PROBIT,R1
  416.        JNE  RNDO10
  417.  
  418.        MOVB @B01,@>8350      Set error - file protected
  419.        B    @DSRRT
  420.  
  421. * The name didn't match.  Adjust the bounds of our search
  422. *
  423. RNDO6  C    R0,R1            Anything left to check
  424.        JEQ  RNDO8
  425.        MOV  R0,R4            Adjust lower bound of search
  426.        A    R1,R4
  427.        SRL  R4,1
  428.        MOV  R4,R0
  429.        INC  R0
  430.        B    @RNDO2
  431.  
  432. RNDO7  C    R0,R1
  433.        JEQ  RNDO8
  434.        MOV  R0,R4            Adjust upper bound of search
  435.        A    R1,R4
  436.        SRL  R4,1
  437.        C    R4,R0
  438.        JEQ  RNDO8
  439.        MOV  R4,R1
  440.        DEC  R1
  441.        B    @RNDO2
  442.  
  443. * The name didn't exist - return to the caller
  444. *
  445. RNDO8  CLR  R9
  446.        RT
  447.  
  448. * The filename existed and wasn't protected.  Now we have to
  449. * see if the name we want to rename it to already exists
  450. *
  451. RNDO10 LI   R4,10            Copy the new name to the FNCB
  452.        LI   R5,FNCB
  453.        LI   R7,RNNEW
  454. RNDO11 LDCR @B02,4
  455.        MOV  *R7+,R8
  456.        LDCR @ZERO,4
  457.        MOV  R8,*R5+
  458.        DECT R4
  459.        JNE  RNDO11
  460.  
  461.        LDCR @B02,4
  462.        MOV  @RNLOW,R0        Get bounds of search
  463.        MOV  @RNHIGH,R1
  464.        C    R0,R1            If equal, new filename
  465.        JNE  RND11A           exists already
  466.        C    @LONAM,@ZERO
  467.        JNE  RN15A
  468. RND11A
  469.  
  470. * Here are some check to see if we have to scan the
  471. * directory again
  472.  
  473. * Check 1 - If the name we want to rename to comes before
  474. *           the first file in the directory, we can skip
  475. *           processing
  476.  
  477.        CI   R1,0
  478.        JEQ  RNDO19
  479.  
  480. * Check 2 - If R0 and R1 are off by only 1, we know the new
  481. *           file will go between them.
  482.  
  483.        DEC  R1
  484.        C    R1,R0
  485.        JNE  RND11B
  486.        C    @LONAM,@ZERO
  487.        JNE  RNDO18
  488. RND11B
  489.        C    @LONAM,@ZERO
  490.        JEQ  RNDO12
  491.        INC  R0
  492. RNDO12
  493.        MOV  R0,R4            Calculate the midpoint
  494.        A    R1,R4
  495.        ANDI R4,>FFFE
  496.        A    R3,R4
  497.        LDCR R2,4
  498.        MOV  *R4,R7           Get AU
  499.  
  500.        LDCR @B04,4
  501.        MOV  R6,R4
  502.        SRL  R4,8
  503.        SLA  R4,1
  504.        MPY  @SAUTBL(R4),R7
  505.  
  506.        LI   R4,SECBUF
  507.        SRL  R8,1
  508.        JNC  RNDO13
  509.        AI   R4,>100
  510. RNDO13 SRL  R7,1
  511.        JNC  RNDO14
  512.        ORI  R8,>8000
  513. RNDO14 LDCR @ZERO,4
  514.        BLWP @BANKIT
  515.        DATA SCSIRD
  516.        JNE  RNDER6
  517.  
  518. * Compare the names to see if we have a match
  519. *
  520. RNDO15 LI   R5,FNCB
  521. RN15B  C    *R4+,*R5+
  522.        JL   RNDO16
  523.        JH   RNDO17
  524.        CI   R5,FNCB+10
  525.        JNE  RN15B
  526.  
  527. * The new name exists - error!!!
  528. *
  529. RN15A  LDCR @ZERO,4
  530.        MOVB @B07,@>8350
  531.        B    @DSRRT
  532.  
  533. RNDO16 C    R0,R1            Is there anything left to check?
  534.        JEQ  RNDO18
  535.        MOV  R0,R4
  536.        A    R1,R4
  537.        SRL  R4,1
  538.        MOV  R4,R0
  539.        INC  R0
  540.        JMP  RNDO12
  541.  
  542. RNDO17 C    R0,R1            Is there anything left to check?
  543.        JEQ  RNDO19
  544.        MOV  R0,R4
  545.        A    R1,R4
  546.        SRL  R4,1
  547.        C    R4,R0
  548.        JEQ  RNDO19
  549.        MOV  R4,R1
  550.        DEC  R1
  551.        JMP  RNDO12
  552.  
  553. **
  554. *
  555. * Here is where we go if there is an error doing
  556. * I/O to the SCSI drive
  557. *
  558. **
  559.  
  560. RNDER6 MOVB @B06,@>8350
  561.        B    @DSRRT
  562.  
  563. *******************
  564.  
  565. RNDO18 INC  R0
  566. RNDO19
  567.  
  568. * We now have the index where the file will go.  Based on
  569. * where it was, we wither have to move the pointers forward,
  570. * backward, or not at all.
  571.  
  572.        SLA  R0,1
  573.  
  574.        LI   R1,-2
  575.        LDCR @B02,4
  576.        MOV  @RENMAU,R7
  577.        LDCR R2,4
  578.        MOV  R3,R5
  579. RNDO20 INCT R1
  580.        C    *R5+,R7
  581.        JNE  RNDO20
  582.  
  583.        A    R3,R0
  584.        A    R3,R1
  585.  
  586.        LI   R10,1
  587.        C    R1,R0            See which way we move
  588.        JEQ  RNDO24           No shuffling of list required!!
  589.        JH   RNDO22
  590.  
  591. * OK, We have to move pointers
  592. *
  593.        DECT R0
  594.        C    R0,R1
  595.        JEQ  RNDO24
  596. RNDO21 MOV  @2(R1),*R1
  597.        INCT R1
  598.        C    R1,R0
  599.        JNE  RNDO21
  600.        JMP  RNDO23
  601.  
  602. * We have to move pointers the other way
  603. RNDO22 MOV  @-2(R1),*R1
  604.        DECT R1
  605.        C    R1,R0
  606.        JNE  RNDO22
  607.  
  608. RNDO23 MOV  R7,*R1
  609.        LI   R10,2
  610. * Now lets overwrite the name in the FDR or DDR
  611. *
  612. RNDO24 LDCR @B04,4
  613.        MOV  R6,R5
  614.        SRL  R5,8
  615.        SLA  R5,1
  616.        MPY  @SAUTBL(R5),R7
  617.  
  618.        LI   R5,SECBUF
  619.        SRL  R8,1
  620.        JNC  RNDO25
  621.        AI   R5,>100
  622. RNDO25 SRL  R7,1
  623.        JNC  RNDO26
  624.        ORI  R8,>8000
  625. RNDO26 LDCR @ZERO,4
  626.        BLWP @BANKIT
  627.        DATA SCSIRD
  628.        JNE  RNDER6
  629.  
  630. * Now copy the filename over the old one
  631. * Lucky for us, it's still in the FNCB
  632.  
  633.        LI   R4,10
  634.        LI   R9,FNCB
  635. RNDO27 MOV  *R9+,*R5+
  636.        DECT R4
  637.        JNE  RNDO27
  638.  
  639. * Now write it out back to disk
  640. *
  641.        BLWP @BANKIT
  642.        DATA SCSIWT
  643.        JNE  RNDER6
  644.  
  645. * We are done - Success!!
  646.  
  647.        MOV  R10,R9
  648.        RT
  649.